package com.qf.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.qf.exceptions.ResultCode;

import javax.xml.transform.Result;

/**
 *当当前类是接口的统一的返回结果类
 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)//只解析不为空的数据."" 也算空,也就是只返回有效数据
public class R {

    private int code;//状态码
    private String msg;//提示信息

    private Object data;//携带的数据


    public static R setOK(){
        return setOK(null);
    }

    public static R setOK(Object data){
//        R result = new R();
//        result.setCode(ResultCode.SUCCESS);
//        result.setMsg("成功");
//        result.setData(data);
//        return result;
        return setError(ResultCode.SUCCESS,"成功",data);
    }

    public static R setError(int code,String msg){
        return setError(code,msg,null);
    }

    public static R setError(int code,String msg,Object data){
        R result = new R();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }


}
